/**
 * Created by dale on 2017/9/7.
 */
var teachList;
$(document).ready(function () {

    var form = new xhForm($('#xh_form'));
    form.parse();

    $('#fileInput').fileinput({
        language: 'zh', //设置语言
        uploadUrl: '', //上传的地址
        allowedFileExtensions : ['jpg', 'png','gif','xlsx','docx','pdf','xls'],//接收的文件后缀
        uploadAsync: true, //默认异步上传
        showUpload: true, //是否显示上传按钮
        showCaption: false,//是否显示标题
        dropZoneEnabled: false,
        showPreview:false,
        browseClass: "btn btn-primary", //按钮样式
        maxFileSize: 6000,
        maxFileCount: 10, //表示允许同时上传的最大文件个数
        enctype: 'multipart/form-data',
        validateInitialCount:true,
        height:200,
        previewFileIcon: "<i class='glyphicon glyphicon-king'></i>",
        msgFilesTooMany: "选择上传的文件数量({n}) 超过允许的最大数值{m}！"
    });
    teachList=$('#teachList');
    var tag=1;
    teachList.treegrid({
        onSelect:function (row) {
            if(tag==1){
                appendTeacher(row['keyId'],row['name'],true);
            }
        },
        onUnselect:function (row) {
            if(tag==1){
                $('#teachTable [class='+row['keyId']+']').remove();
            }
        },
        onBeforeSelect:function (row) {
            if(tag==2){
                return false;
            }
        },
        onBeforeCheck:function (row) {

        },
        onLoadSuccess:function (row) {  //成功加载后设置初始值并禁用
            teachList.treegrid('select','T-36480');
            teachList.treegrid('select','T-27906');
            tag=2;

        }
    });


    function appendTeacher(keyId,$name,$reply) {

        var contentStr ='<tr class="'+keyId+'">'
                            +'<td width="75px"><label >教师名称</label></td>'
                            +'<td style="width: 150px"><input class="form-control" name="teacherName"  value="'+$name+'" readonly></td>'
                            +'<td></td>'
                            +'<td></td>'
                       +'</tr>';

        contentStr =contentStr+'<tr class="'+keyId+'">'
                        +'<td><label >要求</label></td>'
                        +'<td colspan="3"><textarea rows="2" class="form-control" name="mDesc"></textarea></td> '
                    +'</tr>';

        if($reply){
            contentStr =contentStr+'<tr class="'+keyId+'">'
                +'<td><label >回复</label></td>'
                +'<td colspan="3"><textarea rows="2" class="form-control" name="mDesc"></textarea></td>'
                +'</tr>';
        }
        $('#teachTable').prepend(contentStr);
    }
});